<?php require_once('../Connections/fastfood_con.php'); ?>
<?php
// Load the common classes
require_once('../includes/common/KT_common.php');

// Load the tNG classes
require_once('../includes/tng/tNG.inc.php');

// Load the KT_back class
require_once('../includes/nxt/KT_back.php');

// Make a transaction dispatcher instance
$tNGs = new tNG_dispatcher("../");

// Make unified connection variable
$conn_fastfood_con = new KT_connection($fastfood_con, $database_fastfood_con);

//Start Restrict Access To Page
$restrict = new tNG_RestrictAccess($conn_fastfood_con, "../");
//Grand Levels: Any
$restrict->Execute();
//End Restrict Access To Page

// Start trigger
$formValidation = new tNG_FormValidation();
$tNGs->prepareValidation($formValidation);
// End trigger

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_leftmenu = "-1";
if (isset($_GET['id'])) {
  $colname_leftmenu = $_GET['id'];
}
mysql_select_db($database_fastfood_con, $fastfood_con);
$query_leftmenu = sprintf("SELECT * FROM left_menu WHERE id = %s ORDER BY my_pos ASC", GetSQLValueString($colname_leftmenu, "int"));
$leftmenu = mysql_query($query_leftmenu, $fastfood_con) or die(mysql_error());
$row_leftmenu = mysql_fetch_assoc($leftmenu);
$totalRows_leftmenu = mysql_num_rows($leftmenu);

// Make an insert transaction instance
$ins_left_menu = new tNG_multipleInsert($conn_fastfood_con);
$tNGs->addTransaction($ins_left_menu);
// Register triggers
$ins_left_menu->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Insert1");
$ins_left_menu->registerTrigger("BEFORE", "Trigger_Default_FormValidation", 10, $formValidation);
$ins_left_menu->registerTrigger("END", "Trigger_Default_Redirect", 99, "../includes/nxt/back.php");
// Add columns
$ins_left_menu->setTable("left_menu");
$ins_left_menu->addColumn("my_link", "STRING_TYPE", "POST", "my_link");
$ins_left_menu->addColumn("my_order", "NUMERIC_TYPE", "POST", "my_order");
$ins_left_menu->addColumn("my_menu", "STRING_TYPE", "POST", "my_menu");
$ins_left_menu->addColumn("my_pos", "NUMERIC_TYPE", "POST", "my_pos");
$ins_left_menu->setPrimaryKey("id", "NUMERIC_TYPE");

// Make an update transaction instance
$upd_left_menu = new tNG_multipleUpdate($conn_fastfood_con);
$tNGs->addTransaction($upd_left_menu);
// Register triggers
$upd_left_menu->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Update1");
$upd_left_menu->registerTrigger("BEFORE", "Trigger_Default_FormValidation", 10, $formValidation);
$upd_left_menu->registerTrigger("END", "Trigger_Default_Redirect", 99, "../includes/nxt/back.php");
// Add columns
$upd_left_menu->setTable("left_menu");
$upd_left_menu->addColumn("my_link", "STRING_TYPE", "POST", "my_link");
$upd_left_menu->addColumn("my_order", "NUMERIC_TYPE", "POST", "my_order");
$upd_left_menu->addColumn("my_menu", "STRING_TYPE", "POST", "my_menu");
$upd_left_menu->addColumn("my_pos", "NUMERIC_TYPE", "POST", "my_pos");
$upd_left_menu->setPrimaryKey("id", "NUMERIC_TYPE", "GET", "id");

// Make an instance of the transaction object
$del_left_menu = new tNG_multipleDelete($conn_fastfood_con);
$tNGs->addTransaction($del_left_menu);
// Register triggers
$del_left_menu->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Delete1");
$del_left_menu->registerTrigger("END", "Trigger_Default_Redirect", 99, "../includes/nxt/back.php");
// Add columns
$del_left_menu->setTable("left_menu");
$del_left_menu->setPrimaryKey("id", "NUMERIC_TYPE", "GET", "id");

// Execute all the registered transactions
$tNGs->executeTransactions();

// Get the transaction recordset
$rsleft_menu = $tNGs->getRecordset("left_menu");
$row_rsleft_menu = mysql_fetch_assoc($rsleft_menu);
$totalRows_rsleft_menu = mysql_num_rows($rsleft_menu);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="../includes/skins/mxkollection3.css" rel="stylesheet" type="text/css" media="all" />
<script src="../includes/common/js/base.js" type="text/javascript"></script>
<script src="../includes/common/js/utility.js" type="text/javascript"></script>
<script src="../includes/skins/style.js" type="text/javascript"></script>
<?php echo $tNGs->displayValidationRules();?>
<script src="../includes/nxt/scripts/form.js" type="text/javascript"></script>
<script src="../includes/nxt/scripts/form.js.php" type="text/javascript"></script>
<script type="text/javascript">
$NXT_FORM_SETTINGS = {
  duplicate_buttons: true,
  show_as_grid: true,
  merge_down_value: true
}
</script>
</head>

<body>

<?php include ('admin_top.php'); ?>

<?php
	echo $tNGs->getErrorMsg();
?>
<div class="KT_tng">
  <h3 id="adduser">
    <?php 
// Show IF Conditional region1 
if (@$_GET['id'] == "") {
?>
      <?php echo NXT_getResource("Thêm"); ?>
      <?php 
// else Conditional region1
} else { ?>
      <?php echo NXT_getResource("Cập nhật"); ?>
      <?php } 
// endif Conditional region1
?>
    Menu trái </h3>
  <div class="KT_tngform">
    <form method="post" id="form" action="<?php echo KT_escapeAttribute(KT_getFullUri()); ?>">
      <?php $cnt1 = 0; ?>
      <?php do { ?>
        <?php $cnt1++; ?>
        <?php 
// Show IF Conditional region1 
if (@$totalRows_rsleft_menu > 1) {
?>
          <h2><?php echo NXT_getResource("Record_FH"); ?> <?php echo $cnt1; ?></h2>
          <?php } 
// endif Conditional region1
?>
        <table cellpadding="2" cellspacing="0" class="KT_tngtable">
          <tr>
            <td class="KT_th"><label for="my_link_<?php echo $cnt1; ?>">My_link:</label></td>
            <td><input type="text" name="my_link_<?php echo $cnt1; ?>" id="my_link_<?php echo $cnt1; ?>" value="<?php echo KT_escapeAttribute($row_rsleft_menu['my_link']); ?>" size="32" maxlength="200" />
              <?php echo $tNGs->displayFieldHint("my_link");?> <?php echo $tNGs->displayFieldError("left_menu", "my_link", $cnt1); ?></td>
          </tr>
          <tr>
            <td class="KT_th"><label for="my_order_<?php echo $cnt1; ?>">My_order:</label></td>
            <td><input type="text" name="my_order_<?php echo $cnt1; ?>" id="my_order_<?php echo $cnt1; ?>" value="<?php echo KT_escapeAttribute($row_rsleft_menu['my_order']); ?>" size="7" />
              <?php echo $tNGs->displayFieldHint("my_order");?> <?php echo $tNGs->displayFieldError("left_menu", "my_order", $cnt1); ?></td>
          </tr>
          <tr>
            <td class="KT_th"><label for="my_menu_<?php echo $cnt1; ?>">My_menu:</label></td>
            <td><input type="text" name="my_menu_<?php echo $cnt1; ?>" id="my_menu_<?php echo $cnt1; ?>" value="<?php echo KT_escapeAttribute($row_rsleft_menu['my_menu']); ?>" size="32" maxlength="200" />
              <?php echo $tNGs->displayFieldHint("my_menu");?> <?php echo $tNGs->displayFieldError("left_menu", "my_menu", $cnt1); ?></td>
          </tr>
          <tr>
            <td class="KT_th"><label for="my_pos_<?php echo $cnt1; ?>">My:</label></td>
            <td><input type="text" name="my_pos_<?php echo $cnt1; ?>" id="my_pos_<?php echo $cnt1; ?>" value="<?php echo KT_escapeAttribute($row_rsleft_menu['my_pos']); ?>" size="7" />
              <?php echo $tNGs->displayFieldHint("my_pos");?> <?php echo $tNGs->displayFieldError("left_menu", "my_pos", $cnt1); ?></td>
          </tr>
        </table>
        <input type="hidden" name="kt_pk_left_menu_<?php echo $cnt1; ?>" class="id_field" value="<?php echo KT_escapeAttribute($row_rsleft_menu['kt_pk_left_menu']); ?>" />
        <?php } while ($row_rsleft_menu = mysql_fetch_assoc($rsleft_menu)); ?>
      <div class="KT_bottombuttons">
        <div>
          <?php 
      // Show IF Conditional region1
      if (@$_GET['id'] == "") {
      ?>
            <input type="submit" name="KT_Insert1" id="button1" value="<?php echo NXT_getResource("Insert_FB"); ?>" />
            <?php 
      // else Conditional region1
      } else { ?>
            <div class="KT_operations">
              <input type="submit" name="KT_Insert1" value="<?php echo NXT_getResource("Insert as new_FB"); ?>" onclick="nxt_form_insertasnew(this, 'id')" />
            </div>
            <input type="submit" id="button1" name="KT_Update1" value="<?php echo NXT_getResource("Update_FB"); ?>" />
            <input type="submit" name="KT_Delete1" value="<?php echo NXT_getResource("Delete_FB"); ?>" onclick="return confirm('<?php echo NXT_getResource("Are you sure?"); ?>');" />
            <?php }
      // endif Conditional region1
      ?>
          <input type="button" id="button2" name="KT_Cancel1" value="<?php echo NXT_getResource("Cancel_FB"); ?>" onclick="return UNI_navigateCancel(event, '../includes/nxt/back.php')" />
        </div>
      </div>
    </form>
  </div>
  <br class="clearfixplain" />
</div>
<p>&nbsp;</p>


<?php include ('admin_bottom.php'); ?>
</body>
</html>
<?php
mysql_free_result($leftmenu);
?>
